package com.wisdytech.ccdserver.common;

import org.apache.dubbo.common.extension.Activate;
import org.apache.dubbo.rpc.*;

import java.util.HashMap;
import java.util.Map;

/**
 * @author svolt
 */
@Activate
public class DubboProviderContextFilter implements Filter {
    @Override
    public Result invoke(Invoker<?> invoker, Invocation invocation) throws RpcException {
        Map<String, String> context = new HashMap<>();
        // 处理session
        String username = RpcContext.getContext().getAttachment("username");
        String userId = RpcContext.getContext().getAttachment("userId");
        String ip = RpcContext.getContext().getAttachment("ip");
        context.put("username", username);
        context.put("userId",userId);
        context.put("ip",ip);
        RpcContext.getContext().setAttachments(context);

        return invoker.invoke(invocation);
    }
}
